package com.author.document.style;

import java.awt.Color;
import java.util.HashMap;
import java.util.Hashtable;

import javax.swing.JComponent;

public final class StyleChangeNotify extends JComponent {
	/** Name of the property that is being changed */
	private String						propertyName			= null;

	/** List of document properties */
	public static final String			DOCUMENT_STYLE			= "DOCUMENT_STYLE";
	public static final String			FONT_NAME				= "FONT_NAME";
	public static final String			FONT_SIZE				= "FONT_SIZE";

	public static final String			BOLD					= "BOLD";
	public static final String			ITALIC					= "ITALIC";
	public static final String			UNDERLINE				= "UNDERLINE";
	public static final String			SUPERSCRIPT				= "SUPERSCRIPT";
	public static final String			SUBSCRIPT				= "SUBSCRIPT";

	public static final String			LEFT_ALIGN				= "LEFT_ALIGN";
	public static final String			CENTER_ALIGN			= "CENTER_ALIGN";
	public static final String			RIGHT_ALIGN				= "RIGHT_ALIGN";
	public static final String			JUSTIFY_ALIGN			= "JUSTIFY_ALIGN";

	public static final String			SINGLESPACE				= "SINGLESPACE";
	public static final String			ONEHALFSPACE			= "ONEHALFSPACE";
	public static final String			DOUBLESPACE				= "DOUBLESPACE";

	public static final String			BULLET_LIST				= "BULLET_LIST";
	public static final String			NUMBER_LIST				= "NUMBER_LIST";

	public static final String			LEFT_INDENT				= "LEFT_INDENT";

	public static final String			FOREGROUND_COLOR		= "FOREGROUND_COLOR";
	public static final String			BACKGROUND_COLOR		= "BACKGROUND_COLOR";
	public static final String			HILIGHTER_COLOR			= "HILIGHTER_COLOR";

	/** StylePropertyChangeNotify is responsible for managing style changes */
	private static StyleChangeNotify	propertyChangeNotify	= null;

	/** Only a single instance of StylePropertyChangeNotify should exist */
	private static boolean				SINGLE_INSTANCE_CREATED	= false;

	private StyleChangeNotify() {
		if (!SINGLE_INSTANCE_CREATED) {
			SINGLE_INSTANCE_CREATED = true;
		}
	}

	/** All access to property change notify object will happen through here */
	public static StyleChangeNotify getStyleChangeNotify() {
		if (!SINGLE_INSTANCE_CREATED) {
			StyleChangeNotify.propertyChangeNotify = new StyleChangeNotify();
		}
		return StyleChangeNotify.propertyChangeNotify;
	}

	/**
	 * This method will be used when the user tries to change the document style
	 * by making a selection change in the combo box which is responsible for
	 * representing the styles available to the document
	 */
	public void setDocumentStyleChange(String oldstyle, String newstyle) {
		// Check the old and new style fidelity, they must both be valid styles
		if ((oldstyle == null) || (oldstyle == "")) {
			throw new RuntimeException("Can't change from an unknown style");
		}
		if ((newstyle == null) || (newstyle == "")) {
			throw new RuntimeException("Can't change to an unknown style");
		}

		// update document style property
		propertyName = StyleChangeNotify.DOCUMENT_STYLE;
		firePropertyChange(propertyName, oldstyle, newstyle);
	}

	/**
	 * This method will be used when the user tries to change the document font
	 * by making a selection change in the combo box which is responsible for
	 * representing the fonts available of the document
	 */
	public void setDocumentFontChange(String oldfont, String newfont) {
		// check old and new font fidelity, they must be valid
		if ((oldfont == null) || (oldfont == "")) {
			throw new RuntimeException("Can't change from an unknown style");
		}
		if ((newfont == null) || (newfont == "")) {
			throw new RuntimeException("Can't change to an unknown style");
		}

		// update document font name
		propertyName = StyleChangeNotify.FONT_NAME;
		firePropertyChange(propertyName, oldfont, newfont);
	}

	/**
	 * This method will be used when the user tries to change the document font
	 * size by making a selection change in the combo box which is responsible
	 * for representing the font sizes available of the document
	 */
	public void setDocumentFontSizeChange(int oldsize, int newsize) {
		// update document font size
		propertyName = StyleChangeNotify.FONT_SIZE;
		firePropertyChange(propertyName, oldsize, newsize);
	}

	/**
	 * This method will be used when the user clicks on the BOLD action button
	 * to change the BOLD font property of the document text.
	 */
	public void setBold(boolean oldValue, boolean newValue) {
		propertyName = StyleChangeNotify.BOLD;
		firePropertyChange(propertyName, oldValue, newValue);
	}

	/**
	 * This method will be used when the user clicks on the ITALIC action button
	 * to change the ITALIC font property of the document text.
	 */
	public void setItalic(boolean oldValue, boolean newValue) {
		propertyName = StyleChangeNotify.ITALIC;
		firePropertyChange(propertyName, oldValue, newValue);
	}

	/**
	 * This method will be used when the user clicks on the UNDERLINE action
	 * button to change the UNDERLINE font property of the document text.
	 */
	public void setUnderline(boolean oldValue, boolean newValue) {
		propertyName = StyleChangeNotify.UNDERLINE;
		firePropertyChange(propertyName, oldValue, newValue);
	}

	/**
	 * This method will be used when the user clicks on the SUPERSCRIPT action
	 * button to change the SUPERSCRIPT font property of the document text.
	 */
	public void setSuperscript(boolean oldValue, boolean newValue) {
		propertyName = StyleChangeNotify.SUPERSCRIPT;
		firePropertyChange(propertyName, oldValue, newValue);
	}

	/**
	 * This method will be used when the user clicks on the SUBSCRIPT action
	 * button to change the SUBSCRIPT font property of the document text.
	 */
	public void setSubscript(boolean oldValue, boolean newValue) {
		propertyName = StyleChangeNotify.SUBSCRIPT;
		firePropertyChange(propertyName, oldValue, newValue);
	}

	/**
	 * This method will be used when the user clicks on the LEFT ALIGN action
	 * button to change the LEFT ALIGN font property of the document text.
	 */
	public void setAlignmentLeft(boolean oldValue, boolean newValue) {
		propertyName = StyleChangeNotify.LEFT_ALIGN;
		firePropertyChange(propertyName, oldValue, newValue);
	}

	/**
	 * This method will be used when the user clicks on the CENTER ALIGN action
	 * button to change the CENTER ALIGN font property of the document text.
	 */
	public void setAlignmentCenter(boolean oldValue, boolean newValue) {
		propertyName = StyleChangeNotify.CENTER_ALIGN;
		firePropertyChange(propertyName, oldValue, newValue);
	}

	/**
	 * This method will be used when the user clicks on the RIGHT ALIGN action
	 * button to change the RIGHT ALIGN font property of the document text.
	 */
	public void setAlignmentRight(boolean oldValue, boolean newValue) {
		propertyName = StyleChangeNotify.RIGHT_ALIGN;
		firePropertyChange(propertyName, oldValue, newValue);
	}

	/**
	 * This method will be used when the user clicks on the JUSTIFY ALIGN action
	 * button to change the JUSTIFY ALIGN font property of the document text.
	 */
	public void setAlignmentJustify(boolean oldValue, boolean newValue) {
		propertyName = StyleChangeNotify.JUSTIFY_ALIGN;
		firePropertyChange(propertyName, oldValue, newValue);
	}

	/**
	 * This method will be used when the user clicks on the SINGLE SPACE action
	 * button to change the SINGLE SPACE font property of the document text.
	 */
	public void setSingleSpace(boolean oldValue, boolean newValue) {
		propertyName = StyleChangeNotify.SINGLESPACE;
		firePropertyChange(propertyName, oldValue, newValue);
	}

	/**
	 * This method will be used when the user clicks on the ONEHALF SPACE action
	 * button to change the ONEHALF SPACE font property of the document text.
	 */
	public void setOneHalfSpace(boolean oldValue, boolean newValue) {
		propertyName = StyleChangeNotify.ONEHALFSPACE;
		firePropertyChange(propertyName, oldValue, newValue);
	}

	/**
	 * This method will be used when the user clicks on the DOUBLE SPACE action
	 * button to change the DOUBLE SPACE font property of the document text.
	 */
	public void setDoubleSpace(boolean oldValue, boolean newValue) {
		propertyName = StyleChangeNotify.DOUBLESPACE;
		firePropertyChange(propertyName, oldValue, newValue);
	}

	/**
	 * This method will be used when the user clicks on the LEFT INDENT action
	 * button to change the left indent property of the paragraph
	 */
	public void setLeftIndent(String oldValue, String newValue) {
		propertyName = StyleChangeNotify.LEFT_INDENT;
		firePropertyChange(propertyName, oldValue, newValue);
	}

	/**
	 * This method is used to set the foreground color of the font
	 */
	public void setForegroundColor(Object oldValue, Object newValue) {
		propertyName = StyleChangeNotify.FOREGROUND_COLOR;
		firePropertyChange(propertyName, oldValue, newValue);
	}

	public void setBackgroundColor(Color oldValue, Color newValue) {
		propertyName = StyleChangeNotify.BACKGROUND_COLOR;
		firePropertyChange(propertyName, oldValue, newValue);
	}
}
